--*-----------------------------------------------------------------------------
--
-- ALBUM
--
--*-----------------------------------------------------------------------------
IF NOT EXISTS(
  SELECT 1
    FROM information_schema.tables
   WHERE table_name = 'ALBUM'
)
BEGIN
  CREATE TABLE ALBUM
  (
    ID INT IDENTITY(1,1) NOT NULL
  , NAME NVARCHAR(200) NOT NULL
  , HIKE_ID INT NOT NULL
  , DESCRIPTION NVARCHAR(MAX)
  , PUBLISHED BIT NOT NULL
  , META NVARCHAR(MAX)
  )
  ALTER TABLE ALBUM ADD CONSTRAINT PK_ALBUM PRIMARY KEY(ID)
  ALTER TABLE ALBUM ADD CONSTRAINT FK_ALBUM_HIKE FOREIGN KEY (HIKE_ID) REFERENCES HIKE(ID) ON DELETE CASCADE
  ALTER TABLE ALBUM ADD CONSTRAINT DF_ALBUM_PUBLISHED DEFAULT (0) FOR PUBLISHED
  CREATE INDEX IDX_ALBUM_HIKE ON ALBUM(HIKE_ID)
END
GO
